using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PHMEE.PHM.Algorithms.Basic;
using PHMEE.PHM.Algorithms.Diagnosis;

namespace PHMEE.PHM.Algorithms;

public static class PHMEEPHMAlgorithmsConfigureServices
{
    public static void PHMAlgorithmsConfigureServices(this IServiceCollection services, IConfiguration configuration)
    {
        var grpcServerAddress = configuration["PHMAlgorithmsSettings:GRpcServerAddress"];
        if (string.IsNullOrWhiteSpace(grpcServerAddress))
        {
            // ReSharper disable once NotResolvedInText
            throw new ArgumentNullException("PHMAlgorithmsSettings:GRpcServerAddress", 
                message: "PHMAlgorithmsSettings:GRpcServerAddress in appsettings.json is null or empty.");
        }
        
        var grpcServerAddressUri = new Uri(grpcServerAddress);

        #region Basic Algorithms
        
        services.AddGrpcClient<AccToVelService.AccToVelServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<AccToVelAlg>();

        services.AddGrpcClient<FilterEnvelopeService.FilterEnvelopeServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<FilterEnvelopeAlg>();
        
        services.AddGrpcClient<TrendFeaService.TrendFeaServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<TrendFeaAlg>();
        
        services.AddGrpcClient<CepstrumService.CepstrumServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<CepstrumAlg>();
        
        services.AddGrpcClient<FftService.FftServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<FftAlg>();
        
        services.AddGrpcClient<PowerSpectrumService.PowerSpectrumServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<PowerSpectrumAlg>();
        
        #endregion Basic Algorithms

        #region Diagnosis Algorithms

        services.AddGrpcClient<MainLubricatingOilPumpService.MainLubricatingOilPumpServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<MainLubricatingOilPumpAlg>();
        
        services.AddGrpcClient<AirCompressorService.AirCompressorServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<AirCompressorAlg>();
        
        services.AddGrpcClient<OilFuelSeparatorService.OilFuelSeparatorServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<OilFuelSeparatorAlg>();
        
        services.AddGrpcClient<AirBlower1Service.AirBlower1ServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<AirBlowerAlg1>();
        
        services.AddGrpcClient<AirBlower2Service.AirBlower2ServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<AirBlowerAlg2>();
        
        services.AddGrpcClient<TurbineService.TurbineServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<TurbineAlg>();
        
        services.AddGrpcClient<DieselGeneratorService.DieselGeneratorServiceClient>(options =>
        {
            options.Address = grpcServerAddressUri;
        });
        services.AddTransient<DieselGeneratorAlg>();

        #endregion Diagnosis Algorithms
    }
}